import {Component} from "@angular/core";
import {NavController, ToastController} from "ionic-angular";
import {FeedbackService} from "../../service/feedback/feedback.service";
import {AlertController} from 'ionic-angular';

@Component({
  selector: 'page-feedback',
  templateUrl: 'feedback.html',
  providers: [FeedbackService]
})
export class FeedbackPage {


  private feedbackData: any = {content: null, contactInformation: null};

  constructor(private navCtrl: NavController,
              private feedbackService: FeedbackService,
              private toast: ToastController,
              private alertCtrl: AlertController) {
  }

  feedback() {
    if (!this.feedbackData.content) {
      this.alertCtrl.create({
        subTitle: '请输入反馈内容',
        buttons: [{
          text: '确认',
          handler: () => {
            //this.navCtrl.push(AccountPage)
          }
        }]
      }).present();
      return;
    }
    this.feedbackService.feedback(this.feedbackData).subscribe(res => {
      if (res.status === "SUCCESS") {
        this.alertCtrl.create({
          subTitle: '感谢您的反馈',
          buttons: [{
            text: '确认',
            handler: () => {
              this.navCtrl.pop()
            }
          }]
        }).present();
      } else {
        this.toast.create({
          message: res.message,
          duration: 2000,
          position: 'top'
        }).present();
      }
    }, () => {
      this.toast.create({
        message: "反馈失败,请重试!",
        duration: 2000,
        position: 'top'
      }).present();
    });
  }
}
